package com.haste.controller;

import com.haste.service.HystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName:HystrixController
 * @Description:
 * @Author:Haste
 * @Date:2021/2/8 10:02
 */
@RestController
@DefaultProperties(defaultFallback = "reminder") //全局降级处理
public class HystrixController {
    @Resource
    private HystrixService hystrixService;

    @GetMapping("/order/getInfo/{id}")
    public String getInfo(@PathVariable("id") Integer id){
        return hystrixService.paymentInfo(id);
    }

    @GetMapping("/order/getTimeout/{id}")
    @HystrixCommand
    public String getTimeout(@PathVariable("id") Integer id){
        return hystrixService.paymentInfoTimeout(id);
    }

    public String reminder(){
        return "系统繁忙，稍后再试！全局fallback";
    }
}
